import dayjs from 'dayjs'
import distance from 'gps-distance'

/**
 * 计算两个经纬度之间的距离
 * @param start "经度:纬度"
 * @param end "经度:纬度"
 */
export function calcDistance(start: string, end: string) {
  const startTmp = start.split(':')
  const endTmp = end.split(':')
  const startLat = +startTmp[1] || 0
  const startLog = +startTmp[0] || 0
  const endLat = +endTmp[1] || 0
  const endLog = +endTmp[0] || 0

  if (startLat === 0 || startLog === 0 || endLat === 0 || endLog === 0) {
    return '距离未知'
  }
  const d = distance(startLat, startLog, endLat, endLog)

  return d.toFixed(1)
}

/**
 * 是否今天
 */
export function isToday(date: number) {
  const now = dayjs().format('YYYY-MM-DD')
  const dest = dayjs(date).format('YYYY-MM-DD')
  return now === dest
}

// export function isTooasdfasdfasdf(date: number) {
//   const now = dayjs().add(1, 'day').format('YYYY-MM-DD')
//   const dest = dayjs(date).format('YYYY-MM-DD')
//   return now === dest
// }
